package com.qyhl.module_practice.newhome.fragment.news;

import com.qyhl.module_practice.common.PracticeUrl;
import com.qyhl.webtv.basiclib.utils.network.EasyHttp;
import com.qyhl.webtv.basiclib.utils.network.callback.SimpleCallBack;
import com.qyhl.webtv.basiclib.utils.network.exception.ApiException;
import com.qyhl.webtv.commonlib.common.CommonUtils;
import com.qyhl.webtv.commonlib.entity.news.NewsBean;

import java.util.List;

public class PracticeHomeNewsModel implements PracticeHomeNewsContract.PracticeHomeNewsModel {
    private PracticeHomeNewsPresenter mPresenter;

    PracticeHomeNewsModel(PracticeHomeNewsPresenter mPresenter) {
        this.mPresenter = mPresenter;
    }

    @Override
    public void getData(String sectionId) {
        EasyHttp.get(PracticeUrl.GET_HOME_NEWS)
                .params("siteId", CommonUtils.getInstance().getSite() + "")
                .params("InnerCode", sectionId)
                .params("ID", "0")
                .params("tagName", CommonUtils.getInstance().getSiteName())
                .execute(new SimpleCallBack<List<NewsBean>>() {
                    @Override
                    public void onError(ApiException e) {
                        mPresenter.setError("获取失败！");
                    }

                    @Override
                    public void onSuccess(List<NewsBean> newsBeans) {
                        if (newsBeans != null && newsBeans.size() > 0) {
                            mPresenter.setData(newsBeans);
                        } else {
                            mPresenter.setError("暂无内容");
                        }
                    }
                });

    }
}
